package cn.wolfcode.wms.query;

import cn.wolfcode.wms.util.DateUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

@Getter@Setter
public class SaleChartQueryObject extends QueryObject{

	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date beginDate;
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date endDate;
	
	private long clientId = -1;
	private long brandId = -1;
	//分组
	private String groupByType;
	
	public static Map<String, String> groupByTypes = new LinkedHashMap<>(); 
	static{
		groupByTypes.put("saleman.name", "销售人员");
		groupByTypes.put("product.name", "货品名称");
		groupByTypes.put("client.name", "客户");
		groupByTypes.put("product.brand_name", "品牌");
		groupByTypes.put("DATE_FORMAT(saleaccount.vdate,'%Y-%m')", "销售日期(月)");
		groupByTypes.put("DATE_FORMAT(saleaccount.vdate,'%Y-%m-%d')", "销售日期(日)");
	}
	
	
	public String getGroupByType(){
		if (groupByType==null || "".equals(groupByType.trim())) {
			this.groupByType = "saleman.name";
			return groupByType;
		}
		return groupByType;
	}
	
	public Date getEnDate(){
		if (endDate!=null) {
			return DateUtil.getEndDate(endDate);
		}else {
			return null;
		}
	}
}
